﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GUITest
{
    public partial class WelcomeScreen : Form
    {
        public WelcomeScreen()
        {
            InitializeComponent();
            _resizeLayout();
            ShowWelcomeScreen();
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("SV");
            WelcomeFileMenu.Text = MyLocales.File;
            WelcomeHelpMeny.Text = MyLocales.Help;
            newContestToolStripMenuItem.Text = MyLocales.Create + " " + MyLocales.New + " " + MyLocales.Contest;
        }

        private void EditContestDiscardbutton_Click(object sender, EventArgs e)
        {

        }

        #region WelcomeScreenButtons
        private void CreateContestButton_Click_1(object sender, EventArgs e)
        {
            Welcomepanel.Visible = false;
            EditContestpanel.Visible = true;
        }

        private void StartOrResumeContestButton_Click_1(object sender, EventArgs e)
        {
            ShowRunningContest();
        }

        private void EditOrViewContestsButton_Click_1(object sender, EventArgs e)
        {
            ShowEditContest();
        }
        #endregion

        private void BrowseContestsBackbutton_Click_1(object sender, EventArgs e)
        {
            ShowWelcomeScreen();
        }

        private void Judge1comboBox_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            EditContesttabControl.Visible = false;
            EditContestNewContestantgroupBox.Visible = true;
        }

        private void NewContestantOkbutton_Click(object sender, EventArgs e)
        {
            EditContestNewContestantgroupBox.Visible = false;
            EditContesttabControl.Visible = true;
        }

        private void NewContestantCancelbutton_Click(object sender, EventArgs e)
        {
            EditContestNewContestantgroupBox.Visible = false;
            EditContesttabControl.Visible = true;
        }

        private void EndContestbutton_Click_1(object sender, EventArgs e)
        {
            ShowWelcomeScreen();
        }

        private void DiveQueuelistBox_MouseDoubleClick_1(object sender, MouseEventArgs e)
        {
            if (e.Y > DiveQueuelistBox.SelectedIndex * 15 && e.Y < DiveQueuelistBox.SelectedIndex * 15  + 15 )
            {
                DiveQueuegroupBox.Visible = false;
            EditDiveinQueue.Visible = true;
        }
        }

        private void HistorytreeView_MouseDoubleClick_1(object sender, MouseEventArgs e)
        {
            DiveHistorygroupBox.Visible = false;
            EditDiveinHistorygroupBox.Visible = true;
        }

        private void EditDiveinHistorySaveButton_Click_1(object sender, EventArgs e)
        {
            EditDiveinHistorygroupBox.Visible = false;
            DiveHistorygroupBox.Visible = true;
        }

        private void EditDiveinHistoryDiscardButton_Click_1(object sender, EventArgs e)
        {
            EditDiveinHistorygroupBox.Visible = false;
            DiveHistorygroupBox.Visible = true;
        }

        private void EditDiveinQueueDiscardButton_Click(object sender, EventArgs e)
        {
            EditDiveinQueue.Visible = false;
            DiveQueuegroupBox.Visible = true;
        }

        private void EditDiveinQueueSaveButton_Click(object sender, EventArgs e)
        {
            EditDiveinHistorygroupBox.Visible = false;
            DiveQueuegroupBox.Visible = true;
        }

        private void EditContestpanel_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            Close();
            
        }

        private void ShowWelcomeScreen()
        {
            EditContestpanel.Visible = false;
            EditContestFileMenu.Visible = false;
            EditContestOptionsMenu.Visible = false;
            EditContestHelpMenu.Visible = false;

            RunningContestpanel.Visible = false;
            RunningContestFileMenu.Visible = false;
            RunningContestOptionsMenu.Visible = false;
            RunningContestHelpMenu.Visible = false;

            Welcomepanel.Visible = true;
            WelcomeFileMenu.Visible = true;
            WelcomeHelpMeny.Visible = true; 
            
        }

        private void ShowRunningContest()
        {
            EditContestpanel.Visible = false;
            EditContestFileMenu.Visible = false;
            EditContestOptionsMenu.Visible = false;
            EditContestHelpMenu.Visible = false;

            Welcomepanel.Visible = false;
            WelcomeFileMenu.Visible = false;
            WelcomeHelpMeny.Visible = false;


            RunningContestpanel.Visible = true;
            RunningContestFileMenu.Visible = true;
            RunningContestOptionsMenu.Visible = true;
            RunningContestHelpMenu.Visible = true;
        }

        private void ShowEditContest()
        {
            Welcomepanel.Visible = false;
            WelcomeFileMenu.Visible = false;
            WelcomeHelpMeny.Visible = false;

            RunningContestpanel.Visible = false;
            RunningContestFileMenu.Visible = false;
            RunningContestOptionsMenu.Visible = false;
            RunningContestHelpMenu.Visible = false;

            EditContestpanel.Visible = true;
            EditContestFileMenu.Visible = true;
            EditContestOptionsMenu.Visible = true;
            EditContestHelpMenu.Visible = true; 
        }


        private static void Import_Thread()
        {
            Application.Run(new ImportContestData());
        }

        private void importContestDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var importThread = new System.Threading.Thread(Import_Thread);
            importThread.Start();
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {

        }

        private void WelcomeScreen_ResizeEnd(object sender, EventArgs e)
        {
            _resizeLayout();
        }

        private void _resizeLayout()
        {
            RunningContestpanel.Height = Height;
            RunningContestpanel.Width = Width;
            DiveHistorygroupBox.Width = (Width - 450) / 2 - 20;
            DiveHistorygroupBox.Height = Height - 75;
            HistorytreeView.Width = DiveHistorygroupBox.Width - 20;
            HistorytreeView.Height = DiveHistorygroupBox.Height - 35;
            DiveQueuegroupBox.Height = DiveHistorygroupBox.Height - 195;
            DiveQueuelistBox.Height = DiveQueuegroupBox.Height - 25;
            ResultgroupBox.Width = DiveHistorygroupBox.Width;
            ResultgroupBox.Location = new Point(465 + DiveHistorygroupBox.Width, 3);
            ResultgroupBox.Height = DiveHistorygroupBox.Height;
            listBoxResult.Width = HistorytreeView.Width;
            listBoxResult.Height = HistorytreeView.Height;
        }
    }
}
